﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RobotsEditor.aspx.cs" Inherits="Web.Admin.Page_AdvTools.RobotsEditor" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<!DOCTYPE html>

<%="<!--[if IE 8]> <html class=\"ie8 no-js\"> <![endif]-->"%>
<%="<!--[if IE 9]> <html class=\"ie9 no-js\"> <![endif]-->"%>
<%="<!--[if !IE]><!-->"%>
<html>
<%="<!--<![endif]-->"%>
    <!-- BEGIN HEAD -->

    <head>
        <meta charset="utf-8" />
        <title><%=Evan.Common.CommFun.GetAppSetting("AdminTitle") %> - 后台管理系统</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <!-- #include file="../include/com_res_css.inc" -->

        <link rel="stylesheet" href="<%=SiteConfig.WebAdminPath %>assets/codemirror/lib/codemirror.css">
        <link rel="stylesheet" href="<%=SiteConfig.WebAdminPath %>assets/codemirror/addon/display/fullscreen.css">
        
        <link rel="stylesheet" href="<%=SiteConfig.WebAdminPath %>assets/codemirror/theme/panda-syntax.css">
        <link rel="stylesheet" href="<%=SiteConfig.WebAdminPath %>assets/codemirror/theme/ambiance.css">
        
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/lib/codemirror.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/lib/formatting.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/mode/xml/xml.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/addon/comment/comment.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/addon/comment/continuecomment.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/addon/edit/matchbrackets.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/mode/javascript/javascript.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/mode/htmlmixed/htmlmixed.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/addon/mode/multiplex.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/mode/htmlembedded/htmlembedded.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/mode/css/css.js"></script>
        <script src="<%=SiteConfig.WebAdminPath %>assets/codemirror/addon/display/fullscreen.js"></script>

        <style type="text/css">
            .CodeMirror { height:550px; }
        </style>
    </head>
    <!-- END HEAD -->
    
    <body class="page-header-fixed page-sidebar-closed-hide-logo page-content-white">
        <!-- BEGIN HEADER -->
        
        <!-- #include file="../include/top_bar.inc" -->

        <!-- END HEADER -->
        <!-- BEGIN HEADER & CONTENT DIVIDER -->
        <div class="clearfix"> </div>
        <!-- END HEADER & CONTENT DIVIDER -->
        <!-- BEGIN CONTAINER -->
        <div class="page-container">
            <!-- BEGIN SIDEBAR -->
            
            <!-- #include file="../include/left_menu.inc" -->
            
            <!-- END SIDEBAR -->
            <!-- BEGIN CONTENT -->
            <div class="page-content-wrapper">
                <!-- BEGIN CONTENT BODY -->
                <div class="page-content">
                    <!-- BEGIN PAGE HEADER-->
                    <!-- BEGIN THEME PANEL -->
                    <!-- #include file="../include/theme_panel.inc" -->
                    <h3 class="page-title"> Robots文件编辑 </h3>
                    <!-- END PAGE TITLE-->
                    <!-- END PAGE HEADER-->
                    <!-- BEGIN PAGE CONTENT-->

                                    <div class="portlet light bordered">
                                        <div class="portlet-title tabbable-line">
                                            <div class="nav nav-tabs" style="float:left; padding:12px 13px 13px;">
                                                <a data-toggle="tab" aria-expanded="true"> 文件路径 : <%=FilePath %> </a>
                                                <a data-toggle="tab" class="allowAll" aria-expanded="true">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;允许所有搜索引擎收录&nbsp;&nbsp;</a>
                                                <a data-toggle="tab" class="DisallowAll" aria-expanded="true">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;禁止所有搜索引擎收录 </a>
                                            </div>
                                            <div class="nav nav-tabs" style="float:right; padding:12px 13px 13px;">
                                                <a data-toggle="tab" class="font-red bold" aria-expanded="true"><strong><i class="fa fa-question-circle tooltips code-editor-tips" data-original-title="点击查看详细说明"></i></strong>&nbsp;&nbsp;修改此文件会涉及到搜索引擎抓取 , 请谨慎操作 . <a href="https://ziyuan.baidu.com/robots/index" target="_blank">百度Robots说明</a></a>
                                            </div>
                                        </div>
                                        <div class="tab-content">

                                            <div class="tab-pane active" id="tab_1">
                                                <div class="form">
                                                    <div class="form-horizontal form-row-seperated">

                                                        <%--<div class="form-body">
                                                            操作说明
                                                        </div>--%>
                                                        <br />
                                                        <div class="form-body">
                                                            <textarea id="filecontent" data-cm-mode="aspnet" style="width:100%; height:550px;"><%=FileContent %></textarea>
                                                        </div>

                                                    </div>
                                                </div>
                                            </div>    
                                        </div>

                                        <div class="form-actions form-submit-row">
                                            <div class="form-group">
                                                <label class="control-label col-md-2"></label>
                                                <div class="col-md-8" style="text-align:center;">
                                                    <button type="button" class="btn green submit_template_save"><i class="fa fa-check"></i>&nbsp;&nbsp;提交</button>
                                                    <button type="button" class="btn default jump_index"><i class="fa fa-mail-reply"></i>&nbsp;&nbsp;返回</button>
                                                </div>
                                            </div>
                                            <div class="clear">
                                            </div>
                                        </div>

                                    </div>

                    
                    <!-- END PAGE CONTENT-->
                </div>
                <!-- END CONTENT BODY -->
            </div>
            <!-- END CONTENT -->
            
        </div>
        <!-- END CONTAINER -->
        <!-- #include file="../include/footer.inc" -->
        <!-- #include file="../include/com_res_js.inc" -->

        <div class="problems hide">
            <div style="max-height:600px;overflow:auto;">
                <div style='height:auto'>
                    <div class="note note-info">
                        <h4 class="block">修改文件注意事项</h4>
                        <p> 如果无相关搜索引擎优化知识 , 请勿随意修改<br />修改Robots会直接影响到搜索引擎的收录 , 请谨慎操作</p>
                    </div>
                    <div class="note note-info">
                        <h4 class="block">如果我修改错了怎么办呢 ?</h4>
                        <p> 每一次的修改都会在当前目录生成备份文件<br />备份文件的命名为 robots.18位时间字符.bak , 如果不小心修改出错 , 可去服务器/FTP中恢复 .</p>
                    </div>
                </div>
            </div>
        </div>

    </body>
     <script type="text/javascript">
         $(function () {
             $(".jump_index").on("click", function () {
                 window.location.href = "index.aspx?t=AdvTools";
             });
         });
     </script>
     <script  type="text/javascript">
         $(function () {
             //提交按钮的功能 后台统一提交地址 统管编辑和添加
             $(".submit_template_save").on("click", function () {

                 var ActionType = "修改Robots文件";

                 var _this = this;
                 var model = { FilePath: StrEnCode("<%=FilePath%>"), FileContent: StrEnCode($("#filecontent").val()) };
                 var data = { model: JSON.stringify(model), table: "AdvTools_RobotsEditor", classid: "0", type: "RobotsEditor" };
                 $(_this).button('loading');
                 AjaxSubmit(appConfig.adminPath + "ashx/advtools.ashx", "robotsedit", data, function (f, d) {
                     $(_this).button('reset');
                     if (f) {
                         //请求成功
                         if (parseInt(d.result) > 0) {
                             alert(ActionType + "成功", function () {
                                 setTimeout(function () {
                                     window.location.href = window.location.href;
                                     //if (GetQs("t") == "Versions") {
                                     //    window.location.href = window.location.href;
                                     //} else {
                                     //    JumpList();
                                     //}
                                 }, 500);
                             });
                         }
                         else if (parseInt(d.result) == -99) {
                             alert("登录超时 , 请重新登录", function () {
                                 setTimeout(function () {
                                     JumpLogin();
                                 }, 500);
                             });
                         }
                         else if (parseInt(d.result) == -100) {
                             alert("权限不足 , 无法操作 !");
                         }
                         else {
                             alert(ActionType + "失败 , 请稍后重试 !");
                         }
                     }
                     else {
                         //请求失败
                         alert("请求出错 , 请稍后刷新重试 !");
                     }
                 });
             });
         })
  </script>

    <script type="text/javascript">
        
        $(function () {
            //CodeEditor = CodeMirror.fromTextArea(document.getElementById("filecontent"));
            CodeEditor = CodeMirror.fromTextArea(document.getElementById("filecontent"), {
                lineNumbers: true,
                mode: "application/x-aspx",
                theme: "panda-syntax",
                //theme: "ambiance",
                lineWrapping: true,
                dragDrop: false,
                flattenSpans: false,
                extraKeys: {
                    "F11": function (cm) {
                        cm.setOption("fullScreen", !cm.getOption("fullScreen"));
                    },
                    "Esc": function (cm) {
                        if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
                    },
                    'Ctrl-S': function (cm) {
                        cm.getTextArea().value = cm.getValue();
                        return false;
                    },
                    "F7": function autoFormat(editor) {
                        var totalLines = editor.lineCount();
                        editor.autoFormatRange({ line: 0, ch: 0 }, { line: totalLines });
                    }//代码格式化
                }
            });
            //}).on("change", function (cm, obj) {
            //    //实时将数据存入textarea
            //    cm.getTextArea().value = cm.getValue();
            //});
            CodeEditor.on("change", function (cm, obj) {
                //实时将数据存入textarea
                cm.getTextArea().value = cm.getValue();
            });
            
            console.log(CodeEditor);
            $(".DisallowAll").on("click", function () {
                //CodeEditor.replaceSelection('User-agent: *\tAllow: /');
                CodeEditor.setValue('User-agent: *\rDisallow: /');
            });

            $(".allowAll").on("click", function () {
                CodeEditor.setValue('User-agent: *\rAllow: /');
            });

        })
    </script>

    <script type="text/javascript">
        $(function () {
            $(".code-editor-tips").on("click", function () {
                bootbox.dialog({
                    message: $(".problems").html(),
                    title: "常见问题",
                    buttons:
                    {
                        main:
                        {
                            label: "关闭",
                            className: "blue",
                            callback: function () { }
                        }
                    }
                });
            });
        });
    </script>
</html>

